<template>
  <div>
    <MyHeader background="pink" color="white" title="购物车案例"></MyHeader>
    <div class="main">
      <!-- 3.0利用 v-for遍历每一项数据，渲染到页面-->
      <MyGoods v-for="item in list" :key="item.id" :Glist="item"></MyGoods>
    </div>
    <MyFooter :Flist="list"></MyFooter>
  </div>
</template>

<script>
import MyHeader from "./components/MyHeader.vue";
import MyGoods from "./components/MyGoods.vue";
import MyFooter from "./components/MyFooter.vue";
export default {
  data() {
    return {
      list: [],
    };
  },
  components: {
    MyHeader,
    MyGoods,
    MyFooter,
  },
  // 2.0通过created函数发起axios请求
  // 2.1把获取的list赋值给this.list
  async created() {
    const { data: res } = await this.$axios.get("/api/cart ");
    this.list = res.list;
    console.log(this.list[0]);
  },
};
</script>

<style>
.main {
  padding-top: 45px;
  padding-bottom: 50px;
}
</style>